package cn.usian.controller;

import cn.usian.common.R;
import cn.usian.entity.Dish;
import cn.usian.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;


    @GetMapping("/page")
    public R findPage(@RequestParam(defaultValue = "1")int page,@RequestParam(defaultValue = "10")int pageSize,String name){
        return dishService.findPage(page,pageSize,name);
    }

    //添加
    @PostMapping
    public R save(@RequestBody Dish dish, HttpSession session){
        Long id=(long)session.getAttribute("employee");
        dish.setCreateUser(id);
        dish.setUpdateUser(id);
        dishService.save(dish);
        return R.success("添加成功");
    }

    //批量删除
    @DeleteMapping
    public R del(String ids){
        String[] split = ids.split(",");
        dishService.del(split);
        return R.success("删除成功");
    }

    //批量启售
    @PostMapping("status/0")
    public R tingy(String ids){
        String[] split = ids.split(",");
        dishService.tingy(split);
        return R.success("禁用成功");
    }


    //批量停售
    @PostMapping("status/1")
    public R qiy(String ids){
        String[] split = ids.split(",");
        dishService.qiy(split);
        return R.success("启用成功");
    }
}
